import Sequelize from 'sequelize'
import db from '../database'

const ScheduleInfo = db.define('teacher_course',{
	id:{
		type: Sequelize.INTEGER,
        autoIncrement:true,
        allowNull: false,
        primaryKey:true
	},
    tno:{
    	type:Sequelize.STRING,
    	foreignKey:true
    },
    tname:{
        type:Sequelize.STRING,
        foreignKey:true
    },
    cno:{
    	type:Sequelize.STRING,
    	foreignKey:true
    },
    cname:{
    	type:Sequelize.STRING,
    	foreignKey:true
    },
    classno:{
    	type:Sequelize.STRING,
    	foreignKey:true
    },
    classname:{
        type:Sequelize.STRING,
        foreignKey:true
    }
},{
	freezeTableName:false,
	tableName:'teacher_course',
	updatedAt:'update_time',
    createdAt:'create_time'
});

class ScheduleModel {
	add(record){
		return ScheduleInfo.create(record);
	}

	update(record){
		return ScheduleInfo.update(record,{
			where:{
				id:record.id
			}
		})
	}

	delete(id){
		return ScheduleInfo.destroy({
			where:{
				id:id
			}
		})
	}

	findById(record){
		return ScheduleInfo.findAll({
            where:{
            	tno: record
            }
        });
	}

	findByPage(record){
		return ScheduleInfo.findAndCount({
			limit: record.page_size,
			offset: record.page_size * (record.page_no - 1)
		})
	}

	findAllData(param){
		return ScheduleInfo.findAll({
            where:param
        });
	}
}

module.exports = new ScheduleModel();